﻿<Serializable()> _
Public Class clsNotificationBalloon
	Inherits clsBaseClass

	Private Shared notifyIco As NotifyIcon

	Private eToolTipIcon As ToolTipIcon
	Private strToolTipTitle As String
	Private strToolTipText As String
	Private iToolTipTimeout As Integer

	Public Property ToolTipIcon() As ToolTipIcon
		Get
			Return eToolTipIcon
		End Get
		Set(ByVal value As ToolTipIcon)
			eToolTipIcon = value
		End Set
	End Property

	Public Property ToolTipTitle() As String
		Get
			Return strToolTipTitle
		End Get
		Set(ByVal value As String)
			strToolTipTitle = value
		End Set
	End Property

	Public Property ToolTipText() As String
		Get
			Return strToolTipText
		End Get
		Set(ByVal value As String)
			strToolTipText = value
		End Set
	End Property

	Public Property ToolTipTimeout() As String
		Get
			Return iToolTipTimeout
		End Get
		Set(ByVal value As String)
			iToolTipTimeout = value
		End Set
	End Property

	Public Shared Sub SetNotificationIcon(ByVal ico As NotifyIcon)
		notifyIco = ico
	End Sub

	Public Function ShowBalloonTip() As Boolean
		If notifyIco Is Nothing Then Exit Function
		If ToolTipTitle Is Nothing Then ToolTipTitle = String.Empty
		If ToolTipText Is Nothing Then ToolTipText = String.Empty
		If ToolTipTimeout < 500 Then ToolTipTimeout = 500
		Try
			notifyIco.ShowBalloonTip(ToolTipTimeout, ToolTipTitle, ToolTipText, ToolTipIcon)
			Return True
		Catch ex As Exception
			modCommon.RegisterException(ex)
		End Try
		Return False
	End Function

	Public Overrides Sub Dispose()
		ToolTipTitle = Nothing
		ToolTipText = Nothing
		ToolTipTimeout = Nothing
		MyBase.Dispose()
	End Sub

	Public Overrides Sub GetObjectData(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
		MyBase.GetObjectData(info, context)
		info.AddValue("ToolTipIcon", ToolTipIcon)
		info.AddValue("ToolTipTitle", ToolTipTitle)
		info.AddValue("ToolTipText", ToolTipText)
		info.AddValue("ToolTipTimeout", ToolTipTimeout)
	End Sub

	Protected Overrides Sub Finalize()
		Dispose()
		MyBase.Finalize()
	End Sub

	Public Sub New()
		ToolTipIcon = Windows.Forms.ToolTipIcon.Info
		ToolTipTitle = My.Application.Info.ProductName
		ToolTipText = "Status: OK."
		ToolTipTimeout = 500
	End Sub
End Class
